<?	/*
	// File:	quota.php
	// Purpose:	Scan HD, Users quotas, Domain Transfer
	// Creation:	2002-02-21
	// Author:	Felix <webmaster@can-host.com>
	// Peter Drake (c) 2004
	*/
// Moved to hdquota.mod.phps and bwquota.mod.phps
/*
$mysqldbpath="/var/lib/mysql/";

// Start Group(Domain) HD Quota check
$dbp = mysql_query("SELECT id,owner FROM domains WHERE type='domain'");
while ($data = mysql_fetch_array($dbp)) {
	
	unset($hometotal);
	unset($quotatotal);
	
	if (strlen($data['owner']) < 10 ) {
	
		// neccessary to allow linux to update group quota files
        exec($cfg['prog']['quota']." -g g".$data['id'] ,$quota);

		// calc disk space used by domain in /home/domainname/
		unset($tmpquota);
		if (is_dir($cfg['webdir']."/".$data['id']."/")) {
			exec($cfg['prog']['du']." -s ".$cfg['webdir']."/".$data['id']."/" ,$tmpquota);
			$tmpquota = explode(" ",trim(eregi_replace("[[:space:]]+", " ", $tmpquota[0])));
		}
		$hometotal = $tmpquota[0];
		webcp_log(3,0,'quota',$cfg['webdir']."/".$data['id']."/ size = ".$hometotal,0,$echo);

		// Start User HD Quota check
		$dbp_user = mysql_query("SELECT username FROM users WHERE id='".$data['id']."' AND type != 'demo'");
		while ($data_user = mysql_fetch_array($dbp_user)) {

			unset($mysqlquota);
			unset($userquota);
			unset($usertotal);
			unset($mailquota);
			unset($imapquota);

			// get user disk quota
		    exec($cfg['prog']['quota']." -u ".$data_user['username'], $userquota);
		    if (!$userquota[3]) $num = 2;
			else $num = 3;
		    $userquota = explode(" ",trim(ereg_replace("[[:space:]]+", " ", $userquota[$num])));
			
			// get mysql database disk usage
		    mysql_select_db('mysql');
		    $dbp_mysql = mysql_query("SELECT Db FROM db where User='".substr($data_user['username'],0,16)."'");
		    while ($data_mysql = mysql_fetch_array($dbp_mysql)) {
		        if (is_dir($mysqldbpath.$data_mysql['Db'])) {
		        	unset($tmpquota);
					exec("/usr/bin/du -s ".$mysqldbpath.$data_mysql['Db'] , $tmpquota);
					$tmpquota = explode(" ",trim(eregi_replace("[[:space:]]+", " ", $tmpquota[0])));
		            $mysqlquota = $mysqlquota + $tmpquota[0];
				}
			}
			if (!is_numeric($mysqlquota)) { $mysqlquota = 0; }
			webcp_log(3,0,"quota",$data_user['username']." mysql size = ".$mysqlquota,0,$echo);
	
	        // get INBOX disk usage
	        if (is_file($cfg['mail_spool']."/".$data_user['username'])) {
		        exec("/usr/bin/du -s ".$cfg['mail_spool']."/".$data_user['username'] ,$mailquota);
	    		$mailquota = explode(" ",trim(eregi_replace("[[:space:]]+", " ", $mailquota[0])));
	    		webcp_log(3,0,"quota",$data_user['username']." mail size = ".$mailquota[0],0,$echo);
		    }
	
			// get imap disk usage
			if (is_dir($cfg['uwimapdir']."/".$data_user['username'])) {
				exec("/usr/bin/du -s ".$cfg['uwimapdir']."/".$data_user['username']."/" ,$imapquota);
				$imapquota = explode(" ",trim(eregi_replace("[[:space:]]+", " ", $imapquota[0])));
				webcp_log(3,0,"quota",$data_user['username']." imap folders size = ".$imapquota[0],0,$echo);
			}

			// total user disk usage = disk quota (files+imap) + mysql + INBOX
	        $usertotal = $userquota[1] + $mysqlquota + $mailquota[0] + $imapquota[0];
			webcp_log(3,0,"quota",$data_user['username']." total size = ".$usertotal,0,$echo);

			mysql_select_db($cfg['dbname']);
			mysql_query("UPDATE users SET hd_used=".round($usertotal / 1024,2)." WHERE username='".$data_user['username']."'");

			// this calc the total disk space used outside of /home/domain/
			$quotatotal = $quotatotal + $mysqlquota + $mailquota[0] + $imapquota[0];
		}
	
		// calc the total disk space used; ie. space used in /home/domain plus elsewhere
		$quotatotal = $quotatotal + $hometotal;
		webcp_log(3,0,"quota",$data['id']." "." total size = ".$quotatotal,0,$echo);

		mysql_query("UPDATE domains SET hd_used=".round($quotatotal / 1024,2)." WHERE id='".$data['id']."'"); 
	   
	}
}


// Start Domain Transfer Check (using mod_watch)
unset($data);
$dbp = mysql_query("SELECT id,ip,host,domain,transfer_stat,transfer_used FROM domains");
while ($data = mysql_fetch_array($dbp)) {
	
	// Is the domain really hosted on that (supposedly) correct ip?
	$trueip = gethostbyname($data['host'].".".$data['domain']);
	if ($trueip == $data['ip'] OR $trueip == '127.0.0.1') {
		unset($transfer);
		$transfer = @explode(" ",@trim(@implode("",@file("http://".$data['host'].".".$data['domain']."/watch-info"))));
		if (is_array($transfer)) {
			if ($data['transfer_stat'] <= $transfer[3]) $webtransfer = $transfer[3] - $data['transfer_stat'];
			else $webtransfer = $transfer[3];
			mysql_query("UPDATE domains SET transfer_used = ".($data['transfer_used'] + round($webtransfer / 1024 / 1024 / 1024,5)).", transfer_stat = ".$transfer[3]." WHERE id='".$data['id']."'");
		}
	}
}
*/
?>
